/*******************************************************************************************************/
/*******************************************************************************************************/
//   //                                                                         //
//   // A function to detect the scissor angle at the maximum platform height.                    //
//   // This angle will be used to stop motion, so the cylinder will not drive against its own hard  //
//   // point.                                                                     //
//   //                                                                         //
/*******************************************************************************************************/
/*******************************************************************************************************/
/* */                                                                           //
/* */   #include "load_sensing.h"                                                     //
#include "main.h"
#define ANGLE_OFFET  9

/* */                                                                           //
/*******************************************************************************************************/
/*******************************************************************************************************/
/* */                                                                           //
/* */   unsigned char max_angle(unsigned int   ui_Loaded_Calibrated_Angle_Array[]                  // Input: The array of stored scissor angles
/* */                     , unsigned int  ui_Unloaded_Angle_Sensor_Array[]               // Input: The array of stored scissor angles
/* */                     , unsigned char uc_Load_Sensing_Array_Size                     // Input: The number of elements in each stored array
/* */                     , unsigned int  *ui_Max_Angle)                              // Output: The maximum angle that can be reached, before a hard stop occurs.
/* */                                                                           //
/* */	{																								//
/* */      unsigned int ui_Max_Loaded_Angle;                                             //
/* */      unsigned int ui_Max_Unloaded_Angle;                                           //
/* */      unsigned char uc_Sensor_Polarity;                                             //
/* */                                                                           //
/* */      uc_Sensor_Polarity = 0;                                              //
/* */      if(ui_Loaded_Calibrated_Angle_Array[uc_Load_Sensing_Array_Size - 1] >               //
/* */            ui_Loaded_Calibrated_Angle_Array[0])                                 //
/* */			  uc_Sensor_Polarity = 1;															//	The sensor output increases with increasing angle
           if(uc_Sensor_Polarity)
           {
              ui_Max_Loaded_Angle = ui_Loaded_Calibrated_Angle_Array[uc_Load_Sensing_Array_Size - 1] - ANGLE_OFFET;
              ui_Max_Unloaded_Angle = ui_Unloaded_Angle_Sensor_Array[uc_Load_Sensing_Array_Size - 1] - ANGLE_OFFET;
           }
           else
           {
              ui_Max_Loaded_Angle = ui_Loaded_Calibrated_Angle_Array[uc_Load_Sensing_Array_Size - 1] + ANGLE_OFFET;
              ui_Max_Unloaded_Angle = ui_Unloaded_Angle_Sensor_Array[uc_Load_Sensing_Array_Size - 1] + ANGLE_OFFET;
/* */      }                                                                    //
/* */      *ui_Max_Angle = (ui_Max_Unloaded_Angle + ui_Max_Loaded_Angle) / 2;                     // Average the two calculated angles.
/* */      return uc_Sensor_Polarity;                                                 //
/* */   }                                                                       // End.
/* */                                                                           //
/**********END**********END**********END**********END**********END**********END**********END************/
